package de.rac.vaadin.framework.ui;
/*******************************************************************************
 * A shell for any validator to support immediate translation <br>
 * @author Volodymyr Dobryvechir (dobrivecher@yahoo.com)
 * @version 0.2 31.05.2012  <br>
 ******************************************************************************/
import com.vaadin.data.Validator;
import java.io.*;

public class TranslatedValidator implements Validator {
     
	private static final long serialVersionUID = 1L;
	private String message;
	private TranslatedValidatorGetter getter;
	private Validator validator;
	public TranslatedValidator(String message,ResourcePool resource,TranslatedValidatorGetter getter)
     {
         this.message = message;
         this.getter = getter;
         setProperTranslation(resource);
     }
	public void setProperTranslation(ResourcePool resource)
	{
		String newMessage = resource.getTranslation(message);
		validator = getter.getValidator(newMessage);
	}
     public interface TranslatedValidatorGetter extends Serializable
     {
    	 public Validator getValidator(String message);
     }
	@Override
	public void validate(Object value) throws InvalidValueException {
		validator.validate(value);
	}
	@Override
	public boolean isValid(Object value) {
		return validator.isValid(value);
	}
}
